import { defineStore } from 'pinia'
import { userLogin } from '../api/user'
import {getAuth} from '../api/goods'
import router from '../router'
export const useUser = defineStore('user', {
    state: () => {
        return {
            userinfo: null,
            cart: 0,
            qx:{
                qx1:0,
                qx2:0,
                qx3:0,
                qx4:0,
                qx5:0,
                qx6:0,
                qx7:0,
                qx8:0,
                qx9:0,
                qx10:0,
                qx11:0,
                qx12:0,
                qx13:0,
                qx14:0,
                qx15:0,
                qx16:0,
                qx17:0,
                qx18:0,
                qx19:0,
                qx20:0,
                qx21:0,
                qx22:0,
                qx23:0,
                qx24:0,
                qx25:0,
                
            }
        }
    },
    actions: {
        async userLoginAct(info) {
            let res = await userLogin(info)
            if (res.data.code != 0 && res.data.code != 401) {
                this.userinfo = res.data.data.userinfo
                router.go(-1)
            }
        },

        // 获取权限
        async getAuths() {
            let res = await getAuth(this.userinfo?.token || '')
          
            this.qx.qx1 = res.data.data.index_type_filter
            this.qx.qx2 = res.data.data.index_spec_filter
            this.qx.qx3 = res.data.data.index_brand_filter
            this.qx.qx4 = res.data.data.index_thickness_filter
            this.qx.qx5 = res.data.data.index_technology_filter
            this.qx.qx6 = res.data.data.index_classification_filter


            this.qx.qx7 = res.data.data.index_brand_name
            this.qx.qx8 = res.data.data.index_goodsname
            this.qx.qx9 = res.data.data.index_stock
            this.qx.qx10 = res.data.data.index_alias
            this.qx.qx11 = res.data.data.index_statistics

            // 商品详情
            this.qx.qx12 = res.data.data.goodsinfo_goodsname
            this.qx.qx13 = res.data.data.goodsinfo_spec
            this.qx.qx14 = res.data.data.goodsinfo_stock
            this.qx.qx15 = res.data.data.goodsinfo_sn
            this.qx.qx16 = res.data.data.goodsinfo_technology
            this.qx.qx17 = res.data.data.goodsinfo_classification
            this.qx.qx18 = res.data.data.goodsinfo_square



            this.qx.qx19 = res.data.data.goodsinfo_weight
            this.qx.qx20 = res.data.data.goodsinfo_cube
            this.qx.qx21 = res.data.data.goodsinfo_price
            this.qx.qx22 = res.data.data.goodsinfo_zcfee
            this.qx.qx23 = res.data.data.goodsinfo_other
            this.qx.qx24 = res.data.data.goodsinfo_package


            this.qx.qx25 = res.data.data.goodsinfo_plan
            this.qx.qx26 = res.data.data.goodsinfo_install
            this.qx.qx27 = res.data.data.goodsinfo_order

            this.qx.qx28 = res.data.data.index_typea_filter
            this.qx.qx29 = res.data.data.index_typeb_filter
            this.qx.qx30 = res.data.data.index_typec_filter
            this.qx.qx31 = res.data.data.index_typed_filter
            this.qx.qx32 = res.data.data.index_typee_filter

            console.log(this.qx);


        }
    },
    persist: {
        key: 'UserLoginInfo',
    }
})